package com.atguigu.lease.common.exception;

import com.atguigu.lease.common.result.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * projectName: com.atguigu.lease.common.exception
 *
 * @author: 赵伟风
 * description: 全局异常处理 admin / app模块
 */

@RestControllerAdvice
public class GlobalExceptionHandler {

     //common导入了web场景启动器

    //细化定义异常处理方案  exception  result.fail()

    //public static <T> Result<T> fail(T data) {
    //        return build(data, ResultCodeEnum.FAIL);
    //    }
    @ExceptionHandler(Exception.class)
    public Result<String> exceptionHandler(Exception e){
        e.printStackTrace(); //输出错误信息
        return Result.fail(e.getMessage());
    }


    @ExceptionHandler(LeaseException.class)
    public Result<String> leaseExceptionHandler(LeaseException e){
        e.printStackTrace(); //输出错误信息
        /**
         * public static <T> Result<T> build(int code , String message) {
         *         Result<T> result = build(null);
         *         result.setCode(code);
         *         result.setMessage(message);
         *         return result;
         *     }
         */
        return Result.build(e.getCode(),e.getMessage());
    }



}
